home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / Container.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  63.2 KB  |  2,035 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Container.java    1.148 98/10/22
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.io.PrintStream;
  17. import java.io.PrintWriter;
  18. import java.awt.peer.ContainerPeer;
  19. import java.awt.event.KeyEvent;
  20. import java.awt.event.MouseEvent;
  21. import java.awt.event.FocusEvent;
  22. import java.awt.event.ContainerEvent;
  23. import java.awt.event.ContainerListener;
  24. import java.io.ObjectOutputStream;
  25. import java.io.ObjectInputStream;
  26. import java.io.IOException;
  27. import java.awt.event.AWTEventListener;
  28.  
  29. /**
  30.  * A generic Abstract Window Toolkit(AWT) container object is a component 
  31.  * that can contain other AWT components.
  32.  * <p>
  33.  * Components added to a container are tracked in a list.  The order
  34.  * of the list will define the components' front-to-back stacking order 
  35.  * within the container.  If no index is specified when adding a
  36.  * component to a container, it will be added to the end of the list
  37.  * (and hence to the bottom of the stacking order).
  38.  * @version     1.148 10/22/98
  39.  * @author     Arthur van Hoff
  40.  * @author     Sami Shaio
  41.  * @see       java.awt.Container#add(java.awt.Component, int)
  42.  * @see       java.awt.Container#getComponent(int)
  43.  * @see       java.awt.LayoutManager
  44.  * @since     JDK1.0
  45.  */
  46. public class Container extends Component {
  47.  
  48.     /**
  49.      * The number of components in this container.
  50.      * This value can be null.
  51.      * @serial
  52.      * @see getComponent()
  53.      * @see getComponents()
  54.      * @see getComponentCount()
  55.      */
  56.     int ncomponents;
  57.  
  58.     /** 
  59.      * The components in this container.
  60.      * @serial
  61.      * @see add()
  62.      * @see getComponents()
  63.      */
  64.     Component component[] = new Component[4];
  65.  
  66.     /** 
  67.      * Layout manager for this container.
  68.      * @serial
  69.      * @see doLayout()
  70.      * @see setLayout()
  71.      * @see getLayout()
  72.      */
  73.     LayoutManager layoutMgr;
  74.  
  75.     /**
  76.      * Event router for lightweight components.  If this container
  77.      * is native, this dispatcher takes care of forwarding and 
  78.      * retargeting the events to lightweight components contained
  79.      * (if any).
  80.      * @serial
  81.      */
  82.     private LightweightDispatcher dispatcher;
  83.  
  84.     /*
  85.      * Internal, cached size information.
  86.      * @serial
  87.      * @see getMaximumSize()
  88.      * @see getPreferredSize()
  89.      */
  90.     private Dimension maxSize;
  91.  
  92.     transient ContainerListener containerListener;
  93.  
  94.     /*
  95.      * JDK 1.1 serialVersionUID 
  96.      */
  97.      private static final long serialVersionUID = 4613797578919906343L;
  98.  
  99.     static {
  100.         /* ensure that the necessary native libraries are loaded */
  101.     Toolkit.loadLibraries();
  102.     initIDs();
  103.     }
  104.  
  105.     /**
  106.      * Initialize JNI field and method IDs for fields that may be
  107.        called from C.
  108.      */
  109.     private static native void initIDs();
  110.  
  111.     /**
  112.      * Constructs a new Container. Containers can be extended directly, 
  113.      * but are lightweight in this case and must be contained by a parent
  114.      * somewhere higher up in the component tree that is native.
  115.      * (such as Frame for example).
  116.      */
  117.     public Container() {
  118.     }
  119.  
  120.     /** 
  121.      * Gets the number of components in this panel.
  122.      * @return    the number of components in this panel.
  123.      * @see       java.awt.Container#getComponent
  124.      * @since     JDK1.1
  125.      */
  126.     public int getComponentCount() {
  127.     return countComponents();
  128.     }
  129.  
  130.     /** 
  131.      * @deprecated As of JDK version 1.1,
  132.      * replaced by getComponentCount().
  133.      */
  134.     public int countComponents() {
  135.     return ncomponents;
  136.     }
  137.  
  138.     /** 
  139.      * Gets the nth component in this container.
  140.      * @param      n   the index of the component to get.
  141.      * @return     the n<sup>th</sup> component in this container.
  142.      * @exception  ArrayIndexOutOfBoundsException  
  143.      *                 if the n<sup>th</sup> value does not exist.     
  144.      */
  145.     public Component getComponent(int n) {
  146.     synchronized (getTreeLock()) {
  147.         if ((n < 0) || (n >= ncomponents)) {
  148.         throw new ArrayIndexOutOfBoundsException("No such child: " + n);
  149.         }
  150.         return component[n];
  151.     }
  152.     }
  153.  
  154.     /**
  155.      * Gets all the components in this container.
  156.      * @return    an array of all the components in this container.     
  157.      */
  158.     public Component[] getComponents() {
  159.     return getComponents_NoClientCode();
  160.     }
  161.     // NOTE: This method may be called by privileged threads.
  162.     //       This functionality is implemented in a package-private method 
  163.     //       to insure that it cannot be overridden by client subclasses. 
  164.     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  165.     final Component[] getComponents_NoClientCode() {
  166.     synchronized (getTreeLock()) {
  167.         Component list[] = new Component[ncomponents];
  168.         System.arraycopy(component, 0, list, 0, ncomponents);
  169.         return list;
  170.     }
  171.     } // getComponents_NoClientCode()
  172.  
  173.     /**
  174.      * Determines the insets of this container, which indicate the size 
  175.      * of the container's border. 
  176.      * <p>
  177.      * A <code>Frame</code> object, for example, has a top inset that 
  178.      * corresponds to the height of the frame's title bar. 
  179.      * @return    the insets of this container.
  180.      * @see       java.awt.Insets
  181.      * @see       java.awt.LayoutManager
  182.      * @since     JDK1.1
  183.      */
  184.     public Insets getInsets() {
  185.         return insets();
  186.     }
  187.  
  188.     /**
  189.      * @deprecated As of JDK version 1.1,
  190.      * replaced by <code>getInsets()</code>.
  191.      */
  192.     public Insets insets() {
  193.     if (this.peer != null && this.peer instanceof ContainerPeer) {
  194.         ContainerPeer peer = (ContainerPeer)this.peer;
  195.         return peer.insets();
  196.     }
  197.     return new Insets(0, 0, 0, 0);
  198.     }
  199.  
  200.     /** 
  201.      * Adds the specified component to the end of this container. 
  202.      * @param     comp   the component to be added.
  203.      * @return    the component argument.     
  204.      */
  205.     public Component add(Component comp) {
  206.         addImpl(comp, null, -1);
  207.     return comp;
  208.     }
  209.  
  210.     /**
  211.      * Adds the specified component to this container.
  212.      * It is strongly advised to use the 1.1 method, add(Component, Object),
  213.      * in place of this method.
  214.      */
  215.     public Component add(String name, Component comp) {
  216.     addImpl(comp, name, -1);
  217.     return comp;
  218.     }
  219.  
  220.     /** 
  221.      * Adds the specified component to this container at the given 
  222.      * position. 
  223.      * @param     comp   the component to be added.
  224.      * @param     index    the position at which to insert the component, 
  225.      *                   or <code>-1</code> to insert the component at the end.
  226.      * @return    the component <code>comp</code>
  227.      * @see      #remove
  228.      */
  229.     public Component add(Component comp, int index) {
  230.     addImpl(comp, null, index);
  231.     return comp;
  232.     }
  233.  
  234.     /**
  235.      * Adds the specified component to the end of this container.
  236.      * Also notifies the layout manager to add the component to 
  237.      * this container's layout using the specified constraints object.
  238.      * @param     comp the component to be added
  239.      * @param     constraints an object expressing 
  240.      *                  layout contraints for this component
  241.      * @see       java.awt.LayoutManager
  242.      * @since     JDK1.1
  243.      */
  244.     public void add(Component comp, Object constraints) {
  245.     addImpl(comp, constraints, -1);
  246.     }
  247.  
  248.     /**
  249.      * Adds the specified component to this container with the specified
  250.      * constraints at the specified index.  Also notifies the layout 
  251.      * manager to add the component to the this container's layout using 
  252.      * the specified constraints object.
  253.      * @param comp the component to be added
  254.      * @param constraints an object expressing layout contraints for this
  255.      * @param index the position in the container's list at which to insert
  256.      * the component. -1 means insert at the end.
  257.      * component
  258.      * @see #remove
  259.      * @see LayoutManager
  260.      */
  261.     public void add(Component comp, Object constraints, int index) {
  262.        addImpl(comp, constraints, index);
  263.     }
  264.  
  265.     /**
  266.      * Adds the specified component to this container at the specified
  267.      * index. This method also notifies the layout manager to add 
  268.      * the component to this container's layout using the specified 
  269.      * constraints object.
  270.      * <p>
  271.      * This is the method to override if a program needs to track 
  272.      * every add request to a container. An overriding method should 
  273.      * usually include a call to the superclass's version of the method:
  274.      * <p>
  275.      * <blockquote>
  276.      * <code>super.addImpl(comp, constraints, index)</code>
  277.      * </blockquote>
  278.      * <p>
  279.      * @param     comp       the component to be added.
  280.      * @param     constraints an object expressing layout contraints 
  281.      *                 for this component.
  282.      * @param     index the position in the container's list at which to
  283.      *                 insert the component, where <code>-1</code> 
  284.      *                 means insert at the end.
  285.      * @see       java.awt.Container#add(java.awt.Component)       
  286.      * @see       java.awt.Container#add(java.awt.Component, int)       
  287.      * @see       java.awt.Container#add(java.awt.Component, java.lang.Object)       
  288.      * @see       java.awt.LayoutManager
  289.      * @since     JDK1.1
  290.      */
  291.     protected void addImpl(Component comp, Object constraints, int index) {
  292.     synchronized (getTreeLock()) {
  293.  
  294.         /* Check for correct arguments:  index in bounds,
  295.          * comp cannot be one of this container's parents,
  296.          * and comp cannot be a window.
  297.          */
  298.         if (index > ncomponents || (index < 0 && index != -1)) {
  299.         throw new IllegalArgumentException(
  300.               "illegal component position");
  301.         }
  302.         if (comp instanceof Container) {
  303.         for (Container cn = this; cn != null; cn=cn.parent) {
  304.             if (cn == comp) {
  305.             throw new IllegalArgumentException(
  306.                   "adding container's parent to itself");
  307.             }
  308.         }
  309.         }
  310.         if (comp instanceof Window) {
  311.             throw new IllegalArgumentException(
  312.                  "adding a window to a container");
  313.         }
  314.  
  315.         /* Reparent the component and tidy up the tree's state. */
  316.         if (comp.parent != null) {
  317.         comp.parent.remove(comp);
  318.         }
  319.  
  320.         /* Add component to list; allocate new array if necessary. */
  321.         if (ncomponents == component.length) {
  322.         Component newcomponents[] = new Component[ncomponents * 2];
  323.         System.arraycopy(component, 0, newcomponents, 0, ncomponents);
  324.         component = newcomponents;
  325.         }
  326.         if (index == -1 || index == ncomponents) {
  327.         component[ncomponents++] = comp;
  328.         } else {
  329.         System.arraycopy(component, index, component,
  330.                  index + 1, ncomponents - index);
  331.         component[index] = comp;
  332.         ncomponents++;
  333.         }
  334.         comp.parent = this;
  335.         if (valid) {
  336.         invalidate();
  337.         }
  338.         if (peer != null) {
  339.         comp.addNotify();
  340.         }
  341.         
  342.         /* Notify the layout manager of the added component. */
  343.         if (layoutMgr != null) {
  344.         if (layoutMgr instanceof LayoutManager2) {
  345.             ((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints);
  346.         } else if (constraints instanceof String) {
  347.             layoutMgr.addLayoutComponent((String)constraints, comp);
  348.         }
  349.         }
  350.             if (containerListener != null || 
  351.                 (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) {
  352.                 ContainerEvent e = new ContainerEvent(this, 
  353.                                      ContainerEvent.COMPONENT_ADDED,
  354.                                      comp);
  355.                 processEvent(e);
  356.             }
  357.     }
  358.     }
  359.  
  360.     /** 
  361.      * Removes the component, specified by <code>index</code>, 
  362.      * from this container. 
  363.      * @param     index   the index of the component to be removed.
  364.      * @see #add
  365.      * @since JDK1.1
  366.      */
  367.     public void remove(int index) {
  368.     synchronized (getTreeLock()) {
  369.             Component comp = component[index];
  370.         if (peer != null) {
  371.         comp.removeNotify();
  372.         }
  373.         if (layoutMgr != null) {
  374.         layoutMgr.removeLayoutComponent(comp);
  375.         }
  376.         comp.parent = null;
  377.         System.arraycopy(component, index + 1,
  378.                  component, index,
  379.                  ncomponents - index - 1);
  380.         component[--ncomponents] = null;
  381.         if (valid) {
  382.         invalidate();
  383.         }
  384.             if (containerListener != null ||
  385.                 (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) {
  386.                 ContainerEvent e = new ContainerEvent(this, 
  387.                                      ContainerEvent.COMPONENT_REMOVED,
  388.                                      comp);
  389.                 processEvent(e);
  390.             }
  391.         return;
  392.     }
  393.     }
  394.  
  395.     /** 
  396.      * Removes the specified component from this container.
  397.      * @param comp the component to be removed
  398.      * @see #add
  399.      */
  400.     public void remove(Component comp) {
  401.     synchronized (getTreeLock()) {
  402.         if (comp.parent == this)  {
  403.             /* Search backwards, expect that more recent additions
  404.          * are more likely to be removed.
  405.                  */
  406.                 Component component[] = this.component;
  407.         for (int i = ncomponents; --i >= 0; ) {
  408.             if (component[i] == comp) {
  409.                         remove(i);
  410.             }
  411.         }
  412.         }
  413.     }
  414.     }
  415.  
  416.     /** 
  417.      * Removes all the components from this container.
  418.      * @see #add
  419.      * @see #remove
  420.      */
  421.     public void removeAll() {
  422.     synchronized (getTreeLock()) {
  423.         while (ncomponents > 0) {
  424.         Component comp = component[--ncomponents];
  425.         component[ncomponents] = null;
  426.  
  427.         if (peer != null) {
  428.             comp.removeNotify();
  429.         }
  430.         if (layoutMgr != null) {
  431.             layoutMgr.removeLayoutComponent(comp);
  432.         }
  433.         comp.parent = null;
  434.                 if (containerListener != null ||
  435.                    (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) {
  436.                     ContainerEvent e = new ContainerEvent(this, 
  437.                                      ContainerEvent.COMPONENT_REMOVED,
  438.                                      comp);
  439.                     processEvent(e);
  440.                 }
  441.         }
  442.         if (valid) {
  443.         invalidate();
  444.         }
  445.     }
  446.     }
  447.  
  448.     /** 
  449.      * Gets the layout manager for this container.  
  450.      * @see #doLayout
  451.      * @see #setLayout
  452.      */
  453.     public LayoutManager getLayout() {
  454.     return layoutMgr;
  455.     }
  456.  
  457.     /** 
  458.      * Sets the layout manager for this container.
  459.      * @param mgr the specified layout manager
  460.      * @see #doLayout
  461.      * @see #getLayout
  462.      */
  463.     public void setLayout(LayoutManager mgr) {
  464.     layoutMgr = mgr;
  465.     if (valid) {
  466.         invalidate();
  467.     }
  468.     }
  469.  
  470.     /** 
  471.      * Causes this container to lay out its components.  Most programs 
  472.      * should not call this method directly, but should invoke 
  473.      * the <code>validate</code> method instead.
  474.      * @see java.awt.LayoutManager#layoutContainer
  475.      * @see #setLayout
  476.      * @see #validate
  477.      * @since JDK1.1
  478.      */
  479.     public void doLayout() {
  480.     layout();
  481.     }
  482.  
  483.     /** 
  484.      * @deprecated As of JDK version 1.1,
  485.      * replaced by <code>doLayout()</code>.
  486.      */
  487.     public void layout() {
  488.     LayoutManager layoutMgr = this.layoutMgr;
  489.     if (layoutMgr != null) {
  490.         layoutMgr.layoutContainer(this);
  491.     }
  492.     }
  493.  
  494.     /** 
  495.      * Invalidates the container.  The container and all parents
  496.      * above it are marked as needing to be laid out.  This method can
  497.      * be called often, so it needs to execute quickly.
  498.      * @see #validate
  499.      * @see #layout
  500.      * @see LayoutManager
  501.      */
  502.     public void invalidate() {
  503.     if (layoutMgr instanceof LayoutManager2) {
  504.         LayoutManager2 lm = (LayoutManager2) layoutMgr;
  505.         lm.invalidateLayout(this);
  506.     }
  507.     super.invalidate();
  508.     }
  509.  
  510.     /** 
  511.      * Validates this container and all of its subcomponents.
  512.      * <p>
  513.      * AWT uses <code>validate</code> to cause a container to lay out   
  514.      * its subcomponents again after the components it contains
  515.      * have been added to or modified.
  516.      * @see #validate
  517.      * @see Component#invalidate
  518.      */
  519.     public void validate() {
  520.         /* Avoid grabbing lock unless really necessary. */
  521.     if (!valid) {
  522.         synchronized (getTreeLock()) {
  523.         if (!valid && peer != null) {
  524.                     Cursor oldCursor = getCursor();
  525.             ContainerPeer p = null;
  526.             if (peer instanceof ContainerPeer) {
  527.             p = (ContainerPeer) peer;
  528.             }
  529.             if (p != null) {
  530.             p.beginValidate();
  531.             }
  532.             validateTree();
  533.             valid = true;
  534.             if (p != null) {
  535.             p.endValidate();
  536.             }
  537.         }
  538.         }
  539.     }
  540.     }
  541.  
  542.     /**
  543.      * Recursively descends the container tree and recomputes the
  544.      * layout for any subtrees marked as needing it (those marked as
  545.      * invalid).  Synchronization should be provided by the method
  546.      * that calls this one:  <code>validate</code>.
  547.      */
  548.     protected void validateTree() {
  549.     if (!valid) {
  550.         doLayout();
  551.             Component component[] = this.component;
  552.         for (int i = 0 ; i < ncomponents ; ++i) {
  553.         Component comp = component[i];
  554.         if (   (comp instanceof Container) 
  555.                 && !(comp instanceof Window)
  556.             && !comp.valid) {
  557.             ((Container)comp).validateTree();
  558.         } else {
  559.             comp.validate();
  560.         }
  561.         }
  562.     }
  563.     valid = true;
  564.     }
  565.  
  566.     /**
  567.      * Recursively descends the container tree and invalidates all
  568.      * contained components.
  569.      */
  570.     void invalidateTree() {
  571.         synchronized (getTreeLock()) {
  572.         for (int i = 0; i < ncomponents; ++i) {
  573.             Component comp = component[i];
  574.         if (comp instanceof Container) {
  575.             ((Container)comp).invalidateTree();
  576.         }
  577.         else {
  578.             if (comp.valid) {
  579.                 comp.invalidate();
  580.             }
  581.         }
  582.         }
  583.         if (valid) {
  584.             invalidate();
  585.         }
  586.     }
  587.     }
  588.  
  589.     /**
  590.      * Sets the font of this container.
  591.      * @param f The font to become this container's font.
  592.      * @see Component#getFont
  593.      * @since JDK1.0
  594.      */
  595.     public void setFont(Font f) {
  596.         boolean shouldinvalidate = false;
  597.  
  598.     synchronized (this) {
  599.         Font oldfont = getFont();
  600.         super.setFont(f);
  601.         Font newfont = getFont();
  602.         if (newfont != oldfont && (oldfont == null ||
  603.                        !oldfont.equals(newfont))) {
  604.             shouldinvalidate = true;
  605.         }
  606.     }
  607.  
  608.     if (shouldinvalidate) {
  609.         invalidateTree();
  610.     }
  611.     }
  612.  
  613.     /** 
  614.      * Returns the preferred size of this container.  
  615.      * @return    an instance of <code>Dimension</code> that represents 
  616.      *                the preferred size of this container.
  617.      * @see       java.awt.Container#getMinimumSize       
  618.      * @see       java.awt.Container#getLayout
  619.      * @see       java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
  620.      * @see       java.awt.Component#getPreferredSize
  621.      */
  622.     public Dimension getPreferredSize() {
  623.     return preferredSize();
  624.     }
  625.  
  626.     /** 
  627.      * @deprecated As of JDK version 1.1,
  628.      * replaced by <code>getPreferredSize()</code>.
  629.      */
  630.     public Dimension preferredSize() {
  631.     /* Avoid grabbing the lock if a reasonable cached size value
  632.      * is available.
  633.      */ 
  634.         Dimension dim = prefSize;
  635.         if (dim != null && isValid()) {
  636.         return dim;
  637.     }
  638.     synchronized (getTreeLock()) {
  639.         prefSize = (layoutMgr != null) ?
  640.                    layoutMgr.preferredLayoutSize(this) :
  641.                    super.preferredSize();
  642.         
  643.         return prefSize;
  644.     }
  645.     }
  646.  
  647.     /** 
  648.      * Returns the minimum size of this container.  
  649.      * @return    an instance of <code>Dimension</code> that represents 
  650.      *                the minimum size of this container.
  651.      * @see       java.awt.Container#getPreferredSize       
  652.      * @see       java.awt.Container#getLayout
  653.      * @see       java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
  654.      * @see       java.awt.Component#getMinimumSize
  655.      * @since     JDK1.1
  656.      */
  657.     public Dimension getMinimumSize() {
  658.     return minimumSize();
  659.     }
  660.  
  661.     /** 
  662.      * @deprecated As of JDK version 1.1,
  663.      * replaced by <code>getMinimumSize()</code>.
  664.      */
  665.     public Dimension minimumSize() {
  666.     /* Avoid grabbing the lock if a reasonable cached size value
  667.      * is available.
  668.      */ 
  669.         Dimension dim = minSize;
  670.         if (dim != null && isValid()) {
  671.         return dim;
  672.     }
  673.     synchronized (getTreeLock()) {
  674.         minSize = (layoutMgr != null) ?
  675.            layoutMgr.minimumLayoutSize(this) :
  676.            super.minimumSize();
  677.         return minSize;
  678.     }
  679.     }
  680.  
  681.     /** 
  682.      * Returns the maximum size of this container.  
  683.      * @see #getPreferredSize
  684.      */
  685.     public Dimension getMaximumSize() {
  686.     /* Avoid grabbing the lock if a reasonable cached size value
  687.      * is available.
  688.      */ 
  689.         Dimension dim = maxSize;
  690.         if (dim != null && isValid()) {
  691.         return dim;
  692.     }
  693.     if (layoutMgr instanceof LayoutManager2) {
  694.         synchronized (getTreeLock()) {
  695.         LayoutManager2 lm = (LayoutManager2) layoutMgr;
  696.         maxSize = lm.maximumLayoutSize(this);
  697.         }
  698.     } else {
  699.         maxSize = super.getMaximumSize();
  700.     }
  701.     return maxSize;
  702.     }
  703.  
  704.     /**
  705.      * Returns the alignment along the x axis.  This specifies how
  706.      * the component would like to be aligned relative to other 
  707.      * components.  The value should be a number between 0 and 1
  708.      * where 0 represents alignment along the origin, 1 is aligned
  709.      * the furthest away from the origin, 0.5 is centered, etc.
  710.      */
  711.     public float getAlignmentX() {
  712.     float xAlign;
  713.     if (layoutMgr instanceof LayoutManager2) {
  714.         synchronized (getTreeLock()) {
  715.         LayoutManager2 lm = (LayoutManager2) layoutMgr;
  716.         xAlign = lm.getLayoutAlignmentX(this);
  717.         }
  718.     } else {
  719.         xAlign = super.getAlignmentX();
  720.     }
  721.     return xAlign;
  722.     }
  723.  
  724.     /**
  725.      * Returns the alignment along the y axis.  This specifies how
  726.      * the component would like to be aligned relative to other 
  727.      * components.  The value should be a number between 0 and 1
  728.      * where 0 represents alignment along the origin, 1 is aligned
  729.      * the furthest away from the origin, 0.5 is centered, etc.
  730.      */
  731.     public float getAlignmentY() {
  732.     float yAlign;
  733.     if (layoutMgr instanceof LayoutManager2) {
  734.         synchronized (getTreeLock()) {
  735.         LayoutManager2 lm = (LayoutManager2) layoutMgr;
  736.         yAlign = lm.getLayoutAlignmentY(this);
  737.         }
  738.     } else {
  739.         yAlign = super.getAlignmentY();
  740.     }
  741.     return yAlign;
  742.     }
  743.  
  744.     /** 
  745.      * Paints the container.  This forwards the paint to any lightweight components 
  746.      * that are children of this container.  If this method is reimplemented, 
  747.      * super.paint(g) should be called so that lightweight components are properly
  748.      * rendered.  If a child component is entirely clipped by the current clipping
  749.      * setting in g, paint() will not be forwarded to that child.
  750.      *
  751.      * @param g the specified Graphics window
  752.      * @see   java.awt.Component#update(java.awt.Graphics)
  753.      */
  754.     public void paint(Graphics g) {
  755.     if (isShowing()) {
  756.         int ncomponents = this.ncomponents;
  757.             Component component[] = this.component;
  758.         Rectangle clip = g.getClipRect();
  759.         for (int i = ncomponents - 1 ; i >= 0 ; i--) {
  760.         Component comp = component[i];
  761.         if (comp != null && 
  762.             comp.peer instanceof java.awt.peer.LightweightPeer &&
  763.             comp.visible == true) {
  764.  
  765.             Rectangle cr = comp.getBounds();
  766.             if (( clip == null ) || cr.intersects(clip)) {
  767.             Graphics cg = g.create(cr.x, cr.y, cr.width, cr.height);
  768.             cg.setFont(comp.getFont());
  769.             try {
  770.                 comp.paint(cg);
  771.             } finally {
  772.                 cg.dispose();
  773.             }
  774.             }
  775.         }
  776.         }
  777.     }
  778.     }
  779.  
  780.     /** 
  781.      * Updates the container.  This forwards the update to any lightweight components 
  782.      * that are children of this container.  If this method is reimplemented, 
  783.      * super.update(g) should be called so that lightweight components are properly
  784.      * rendered.  If a child component is entirely clipped by the current clipping
  785.      * setting in g, update() will not be forwarded to that child.
  786.      *
  787.      * @param g the specified Graphics window
  788.      * @see   java.awt.Component#update(java.awt.Graphics)
  789.      */
  790.     public void update(Graphics g) {
  791.         if (isShowing()) {
  792.             if (! (peer instanceof java.awt.peer.LightweightPeer)) {
  793.                 g.clearRect(0, 0, width, height);
  794.             }
  795.             paint(g);
  796.         }
  797.     }
  798.  
  799.     /** 
  800.      * Prints the container.  This forwards the print to any lightweight components 
  801.      * that are children of this container.  If this method is reimplemented, 
  802.      * super.print(g) should be called so that lightweight components are properly
  803.      * rendered.  If a child component is entirely clipped by the current clipping
  804.      * setting in g, print() will not be forwarded to that child.
  805.      *
  806.      * @param g the specified Graphics window
  807.      * @see   java.awt.Component#update(java.awt.Graphics)
  808.      */
  809.     public void print(Graphics g) {
  810.         super.print(g);  // By default, Component.print() calls paint()
  811.  
  812.         int ncomponents = this.ncomponents;
  813.         Component component[] = this.component;
  814.     Rectangle clip = g.getClipRect();
  815.     for (int i = ncomponents - 1 ; i >= 0 ; i--) {
  816.         Component comp = component[i];
  817.         if (comp != null &&
  818.            comp.peer instanceof java.awt.peer.LightweightPeer) {
  819.         Rectangle cr = comp.getBounds();
  820.         if ((clip == null) || cr.intersects(clip)) {
  821.             Graphics cg = g.create(cr.x, cr.y, cr.width, cr.height);
  822.             try {
  823.             comp.print(cg);
  824.             } finally {
  825.             cg.dispose();
  826.             }
  827.         }
  828.         }
  829.     }
  830.     }
  831.  
  832.     /** 
  833.      * Paints each of the components in this container. 
  834.      * @param     g   the graphics context.
  835.      * @see       java.awt.Component#paint
  836.      * @see       java.awt.Component#paintAll
  837.      */
  838.     public void paintComponents(Graphics g) {
  839.         int ncomponents = this.ncomponents;
  840.         Component component[] = this.component;
  841.     for (int i = ncomponents - 1 ; i >= 0 ; i--) {
  842.         Component comp = component[i];
  843.         if (comp != null) {
  844.                 Graphics cg = comp.getGraphics();
  845.         if (cg != null) {
  846.             Rectangle parentRect = g.getClipRect();
  847.  
  848.             // Calculate the clipping region of the child's graphics
  849.             // context, by taking the intersection of the parent's
  850.             // clipRect (if any) and the child's bounds, and then 
  851.             // translating it's coordinates to be relative to the
  852.             // child.
  853.             if (parentRect != null) {
  854.                 Rectangle childRect = comp.getBounds();
  855.             if (childRect.intersects(parentRect) == false) {
  856.                 // Child component is completely clipped out:
  857.                 // ignore.
  858.                 continue;
  859.             }
  860.             Rectangle childClipRect = 
  861.                 childRect.intersection(parentRect);
  862.             childClipRect.translate(-childRect.x, -childRect.y);
  863.             cg.clipRect(childClipRect.x, childClipRect.y,
  864.                     childClipRect.width, childClipRect.height);
  865.             }
  866.             
  867.             try {
  868.                 comp.paintAll(cg);
  869.             } finally {
  870.               cg.dispose();
  871.             }
  872.         }
  873.         }
  874.     }
  875.     }
  876.  
  877.     /** 
  878.      * Prints each of the components in this container. 
  879.      * @param     g   the graphics context.
  880.      * @see       java.awt.Component#print
  881.      * @see       java.awt.Component#printAll
  882.      */
  883.     public void printComponents(Graphics g) {
  884.         int ncomponents = this.ncomponents;
  885.         Component component[] = this.component;
  886.  
  887.         // A seriously sad hack--
  888.         // Lightweight components always paint behind peered components,
  889.         // even if they are at the top of the Z order. We emulate this
  890.         // behavior by making two printing passes: the first for lightweights;
  891.         // the second for heavyweights.
  892.  
  893.         for (int i = ncomponents - 1 ; i >= 0 ; i--) {
  894.             Component comp = component[i];
  895.             if (comp != null && 
  896.                     comp.peer instanceof java.awt.peer.LightweightPeer) {
  897.                 printOneComponent(g, comp);
  898.             }
  899.         }
  900.         for (int i = ncomponents - 1 ; i >= 0 ; i--) {
  901.             Component comp = component[i];
  902.             if (comp != null && 
  903.                     !(comp.peer instanceof java.awt.peer.LightweightPeer)) {
  904.                 printOneComponent(g, comp);
  905.             }
  906.         }
  907.     }
  908.  
  909.     private void printOneComponent(Graphics g, Component comp) {
  910.         Graphics cg = g.create(comp.x, comp.y, comp.width,
  911.                                comp.height);
  912.         cg.setFont(comp.getFont());
  913.         try {
  914.             comp.printAll(cg);
  915.         } finally {
  916.             cg.dispose();
  917.         }
  918.     }
  919.  
  920.     /**
  921.      * Simulates the peer callbacks into java.awt for printing of
  922.      * lightweight Containers.
  923.      * @param     g   the graphics context to use for printing.
  924.      * @see       Component#printAll
  925.      * @see       #printComponents
  926.      */
  927.     void lightweightPrint(Graphics g) {
  928.         super.lightweightPrint(g);
  929.     printComponents(g);
  930.     }
  931.  
  932.     /**
  933.      * Adds the specified container listener to receive container events
  934.      * from this container.
  935.      * If l is null, no exception is thrown and no action is performed.
  936.      *
  937.      * @param    l the container listener
  938.      */ 
  939.     public synchronized void addContainerListener(ContainerListener l) {
  940.     if (l == null) {
  941.         return;
  942.     }
  943.     containerListener = AWTEventMulticaster.add(containerListener, l);
  944.         newEventsOnly = true;    
  945.     }
  946.  
  947.     /**
  948.      * Removes the specified container listener so it no longer receives
  949.      * container events from this container.
  950.      * If l is null, no exception is thrown and no action is performed.
  951.      *
  952.      * @param     l the container listener
  953.      */ 
  954.     public synchronized void removeContainerListener(ContainerListener l) {
  955.     if (l == null) {
  956.         return;
  957.     }
  958.     containerListener = AWTEventMulticaster.remove(containerListener, l);
  959.     }
  960.  
  961.     // REMIND: remove when filtering is done at lower level
  962.     boolean eventEnabled(AWTEvent e) {
  963.         int id = e.getID();
  964.  
  965.         if (id == ContainerEvent.COMPONENT_ADDED ||
  966.             id == ContainerEvent.COMPONENT_REMOVED) {
  967.             if ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
  968.                 containerListener != null) {
  969.                 return true;
  970.             }
  971.             return false;
  972.         }
  973.         return super.eventEnabled(e);
  974.     }          
  975.  
  976.     /**
  977.      * Processes events on this container. If the event is a ContainerEvent,
  978.      * it invokes the processContainerEvent method, else it invokes its
  979.      * superclass's processEvent.
  980.      * @param e the event
  981.      */
  982.     protected void processEvent(AWTEvent e) {
  983.         if (e instanceof ContainerEvent) {
  984.             processContainerEvent((ContainerEvent)e);     
  985.             return;
  986.         }
  987.     super.processEvent(e);
  988.     }
  989.  
  990.     /** 
  991.      * Processes container events occurring on this container by
  992.      * dispatching them to any registered ContainerListener objects.
  993.      * NOTE: This method will not be called unless container events
  994.      * are enabled for this component; this happens when one of the
  995.      * following occurs:
  996.      * a) A ContainerListener object is registered via addContainerListener()
  997.      * b) Container events are enabled via enableEvents()
  998.      * @see Component#enableEvents
  999.      * @param e the container event
  1000.      */  
  1001.     protected void processContainerEvent(ContainerEvent e) {
  1002.         if (containerListener != null) {
  1003.             switch(e.getID()) {
  1004.               case ContainerEvent.COMPONENT_ADDED:
  1005.                 containerListener.componentAdded(e);
  1006.                 break;
  1007.               case ContainerEvent.COMPONENT_REMOVED:
  1008.                 containerListener.componentRemoved(e);
  1009.                 break;
  1010.             }
  1011.         }
  1012.     }
  1013.  
  1014.     /*
  1015.      * Dispatches an event to this component or one of its sub components.
  1016.      * @param e the event
  1017.      */
  1018.     void dispatchEventImpl(AWTEvent e) {
  1019.     if ((dispatcher != null) && dispatcher.dispatchEvent(e)) {
  1020.         // event was sent to a lightweight component.  The
  1021.         // native-produced event sent to the native container
  1022.         // must be properly disposed of by the peer, so it 
  1023.         // gets forwarded.  If the native host has been removed
  1024.         // as a result of the sending the lightweight event, 
  1025.         // the peer reference will be null.
  1026.         e.consume();
  1027.         if (peer != null) {
  1028.         peer.handleEvent(e);
  1029.         }
  1030.         return;
  1031.     }
  1032.     super.dispatchEventImpl(e);
  1033.     }
  1034.  
  1035.     /*
  1036.      * Dispatches an event to this component, without trying to forward
  1037.      * it to any sub components
  1038.      * @param e the event
  1039.      */
  1040.     void dispatchEventToSelf(AWTEvent e) {
  1041.     super.dispatchEventImpl(e);
  1042.     }
  1043.  
  1044.     /**
  1045.      * Fetchs the top-most (deepest) lightweight component that is interested
  1046.      * in receiving mouse events.
  1047.      */
  1048.     Component getMouseEventTarget(int x, int y, boolean includeSelf) {
  1049.     int ncomponents = this.ncomponents;
  1050.         Component component[] = this.component;
  1051.     for (int i = 0 ; i < ncomponents ; i++) {
  1052.         Component comp = component[i];
  1053.         if ((comp != null) && (comp.contains(x - comp.x, y - comp.y)) &&
  1054.         (comp.peer instanceof java.awt.peer.LightweightPeer) &&
  1055.         (comp.visible == true)) {
  1056.         // found a component that intersects the point, see if there is 
  1057.         // a deeper possibility.
  1058.         if (comp instanceof Container) {
  1059.             Container child = (Container) comp;
  1060.             Component deeper = child.getMouseEventTarget(x - child.x, y - child.y, includeSelf);
  1061.             if (deeper != null) {
  1062.             return deeper;
  1063.             }
  1064.         } else {
  1065.             if ((comp.mouseListener != null) || 
  1066.             ((comp.eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0) ||
  1067.             (comp.mouseMotionListener != null) ||
  1068.             ((comp.eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
  1069.             // there isn't a deeper target, but this component is a target
  1070.             return comp;
  1071.             }
  1072.         }
  1073.         }
  1074.     }
  1075.     
  1076.     boolean isPeerOK;
  1077.     boolean    isMouseOverMe;
  1078.     boolean    isMouseListener;
  1079.     boolean    isMotionListener;
  1080.     
  1081.     isPeerOK = (peer instanceof java.awt.peer.LightweightPeer) || includeSelf;
  1082.     isMouseOverMe = contains(x,y);
  1083.     isMouseListener = (mouseListener != null) ||
  1084.               ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0);
  1085.     isMotionListener = (mouseMotionListener != null) ||
  1086.                ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0);
  1087.  
  1088.     // didn't find a child target, return this component if it's a possible target
  1089.     if ( isMouseOverMe && isPeerOK && (isMouseListener || isMotionListener) ) {
  1090.         return this;
  1091.     }
  1092.     // no possible target
  1093.     return null;
  1094.     }
  1095.  
  1096.     /**
  1097.      * This is called by lightweight components that want the containing
  1098.      * windowed parent to enable some kind of events on their behalf.
  1099.      * This is needed for events that are normally only dispatched to 
  1100.      * windows to be accepted so that they can be forwarded downward to 
  1101.      * the lightweight component that has enabled them.
  1102.      */
  1103.     void proxyEnableEvents(long events) {
  1104.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1105.         // this container is lightweight.... continue sending it
  1106.         // upward.
  1107.         parent.proxyEnableEvents(events);
  1108.     } else {
  1109.         // This is a native container, so it needs to host
  1110.         // one of it's children.  If this function is called before
  1111.         // a peer has been created we don't yet have a dispatcher
  1112.         // because it has not yet been determined if this instance
  1113.         // is lightweight.
  1114.         if (dispatcher != null) {
  1115.         dispatcher.enableEvents(events);
  1116.         }
  1117.     }
  1118.     }
  1119.  
  1120.     Window getWindow() {
  1121.         Container w = this;
  1122.         while(!(w instanceof Window)) {
  1123.             w = w.getParent();
  1124.         }
  1125.         return (Window)w;
  1126.     }
  1127.  
  1128.     /**
  1129.      * This is called by lightweight components that have requested focus.
  1130.      * The focus request is propagated upward until a native container is
  1131.      * found, at which point the native container requests focus and records
  1132.      * the component the host is requesting focus for.
  1133.      */
  1134.     void proxyRequestFocus(Component c) {
  1135.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1136.         // this container is lightweight... continue sending it
  1137.         // upward.
  1138.         parent.proxyRequestFocus(c);
  1139.     } else {
  1140.         // This is a windowed container, so record true focus
  1141.         // component and request focus from the native window
  1142.         // if needed.
  1143.         if (dispatcher.setFocusRequest(c)) {
  1144.                 // If the focus is currently somewhere within this Window,
  1145.                 // call the peer to set focus to this Container.  This way,
  1146.                 // we avoid activating this Window if it's not currently
  1147.                 // active.  -fredx, 2-19-98, bug #4111098
  1148.                 Component window = this;
  1149.                 while (!(window instanceof Window))
  1150.                     window = window.getParent();
  1151.                 if (((Window)window).isActive()) {
  1152.                     peer.requestFocus();
  1153.         }
  1154.                 Toolkit.getEventQueue().changeKeyEventFocus(this);
  1155.         }
  1156.     }
  1157.     }
  1158.  
  1159.     /**
  1160.      * @deprecated As of JDK version 1.1,
  1161.      * replaced by <code>dispatchEvent(AWTEvent e)</code>
  1162.      */
  1163.     public void deliverEvent(Event e) {
  1164.     Component comp = getComponentAt(e.x, e.y);
  1165.     if ((comp != null) && (comp != this)) {
  1166.         e.translate(-comp.x, -comp.y);
  1167.         comp.deliverEvent(e);
  1168.     } else {
  1169.         postEvent(e);
  1170.     }
  1171.     }
  1172.  
  1173.     /**
  1174.      * Locates the component that contains the x,y position.  The
  1175.      * top-most child component is returned in the case where there
  1176.      * is overlap in the components.  This is determined by finding
  1177.      * the component closest to the index 0 that claims to contain
  1178.      * the given point via Component.contains().
  1179.      * @param x the <i>x</i> coordinate
  1180.      * @param y the <i>y</i> coordinate
  1181.      * @return null if the component does not contain the position.
  1182.      * If there is no child component at the requested point and the 
  1183.      * point is within the bounds of the container the container itself 
  1184.      * is returned; otherwise the top-most child is returned.
  1185.      * @see Component#contains
  1186.      * @since JDK1.1
  1187.      */
  1188.     public Component getComponentAt(int x, int y) {
  1189.     return locate(x, y);
  1190.     }
  1191.  
  1192.     /**
  1193.      * @deprecated As of JDK version 1.1,
  1194.      * replaced by <code>getComponentAt(int, int)</code>.
  1195.      */
  1196.     public Component locate(int x, int y) {
  1197.     if (!contains(x, y)) {
  1198.         return null;
  1199.     }
  1200.     int ncomponents = this.ncomponents;
  1201.         Component component[] = this.component;
  1202.     for (int i = 0 ; i < ncomponents ; i++) {
  1203.         Component comp = component[i];
  1204.         if (comp != null) {
  1205.         if (comp.contains(x - comp.x, y - comp.y)) {
  1206.             return comp;
  1207.         }
  1208.         }
  1209.     }
  1210.     return this;
  1211.     }
  1212.  
  1213.     /**
  1214.      * Gets the component that contains the specified point.
  1215.      * @param      p   the point.
  1216.      * @return     returns the component that contains the point,
  1217.      *                 or <code>null</code> if the component does 
  1218.      *                 not contain the point. 
  1219.      * @see        java.awt.Component#contains 
  1220.      * @since      JDK1.1 
  1221.      */
  1222.     public Component getComponentAt(Point p) {
  1223.     return getComponentAt(p.x, p.y);
  1224.     }
  1225.  
  1226.     /**
  1227.      * Locates the visible child component that contains the specified
  1228.      * position.  The top-most child component is returned in the case 
  1229.      * where there is overlap in the components.  If the containing child 
  1230.      * component is a Container, this method will continue searching for 
  1231.      * the deepest nested child component.  Components which are not
  1232.      * visible are ignored during the search.<p>
  1233.      *
  1234.      * The findComponentAt method is different from getComponentAt in
  1235.      * that getComponentAt only searches the Container's immediate
  1236.      * children; if the containing component is a Container, 
  1237.      * findComponentAt will search that child to find a nested component.
  1238.      *
  1239.      * @param x the <i>x</i> coordinate
  1240.      * @param y the <i>y</i> coordinate
  1241.      * @return null if the component does not contain the position.
  1242.      * If there is no child component at the requested point and the 
  1243.      * point is within the bounds of the container the container itself 
  1244.      * is returned.
  1245.      * @see Component#contains
  1246.      * @see getComponentAt
  1247.      * @since JDK1.2
  1248.      */
  1249.     public Component findComponentAt(int x, int y) {
  1250.     if (!contains(x, y)) {
  1251.         return null;
  1252.     }
  1253.         int ncomponents = this.ncomponents;
  1254.         Component component[] = this.component;
  1255.         for (int i = 0 ; i < ncomponents ; i++) {
  1256.             Component comp = component[i];
  1257.             if (comp != null) {
  1258.                 if (comp instanceof Container) {
  1259.                     comp = ((Container)comp).findComponentAt(x - comp.x,
  1260.                                                              y - comp.y);
  1261.                 } else {
  1262.                     comp = comp.locate(x - comp.x, y - comp.y);
  1263.                 }
  1264.                 if (comp != null && comp.isVisible()) {
  1265.                     return comp;
  1266.                 }
  1267.             }
  1268.         }
  1269.     return this;
  1270.     }
  1271.  
  1272.     /**
  1273.      * Locates the visible child component that contains the specified
  1274.      * point.  The top-most child component is returned in the case 
  1275.      * where there is overlap in the components.  If the containing child 
  1276.      * component is a Container, this method will continue searching for 
  1277.      * the deepest nested child component.  Components which are not
  1278.      * visible are ignored during the search.<p>
  1279.      *
  1280.      * The findComponentAt method is different from getComponentAt in
  1281.      * that getComponentAt only searches the Container's immediate
  1282.      * children; if the containing component is a Container, 
  1283.      * findComponentAt will search that child to find a nested component.
  1284.      *
  1285.      * @param      p   the point.
  1286.      * @return null if the component does not contain the position.
  1287.      * If there is no child component at the requested point and the 
  1288.      * point is within the bounds of the container the container itself 
  1289.      * is returned.
  1290.      * @see Component#contains
  1291.      * @see getComponentAt
  1292.      * @since JDK1.2
  1293.      */
  1294.     public Component findComponentAt(Point p) {
  1295.         return findComponentAt(p.x, p.y);
  1296.     }
  1297.  
  1298.     /** 
  1299.      * Makes this Container displayable by connecting it to
  1300.      * a native screen resource.  Making a container displayable will
  1301.      * cause any of its children to be made displayable.
  1302.      * This method is called internally by the toolkit and should
  1303.      * not be called directly by programs.
  1304.      * @see Component#isDisplayable
  1305.      * @see #removeNotify
  1306.      */
  1307.     public void addNotify() {
  1308.         synchronized (getTreeLock()) {
  1309.         // addNotify() on the children may cause proxy event enabling
  1310.         // on this instance, so we first call super.addNotify() and
  1311.         // possibly create an lightweight event dispatcher before calling
  1312.         // addNotify() on the children which may be lightweight.
  1313.         super.addNotify();
  1314.         if (! (peer instanceof java.awt.peer.LightweightPeer)) {
  1315.             dispatcher = new LightweightDispatcher(this);
  1316.         }
  1317.         int ncomponents = this.ncomponents;
  1318.             Component component[] = this.component;
  1319.         for (int i = 0 ; i < ncomponents ; i++) {
  1320.             component[i].addNotify();
  1321.         }
  1322.         }
  1323.     }
  1324.  
  1325.     /** 
  1326.      * Makes this Container undisplayable by removing its connection
  1327.      * to its native screen resource.  Make a container undisplayable
  1328.      * will cause any of its children to be made undisplayable. 
  1329.      * This method is called by the toolkit internally and should
  1330.      * not be called directly by programs.
  1331.      * @see Component#isDisplayable
  1332.      * @see #addNotify
  1333.      */
  1334.     public void removeNotify() {
  1335.         synchronized (getTreeLock()) {
  1336.         int ncomponents = this.ncomponents;
  1337.             Component component[] = this.component;
  1338.         for (int i = 0 ; i < ncomponents ; i++) {
  1339.             component[i].removeNotify();
  1340.         }
  1341.         super.removeNotify();
  1342.         }
  1343.     }
  1344.  
  1345.     /**
  1346.      * Checks if the component is contained in the component hierarchy of
  1347.      * this container.
  1348.      * @param c the component
  1349.      * @return     <code>true</code> if it is an ancestor; 
  1350.      *             <code>false</code> otherwise.
  1351.      * @since      JDK1.1
  1352.      */
  1353.     public boolean isAncestorOf(Component c) {
  1354.     Container p;
  1355.     if (c == null || ((p = c.getParent()) == null)) {
  1356.         return false;
  1357.     }
  1358.     while (p != null) {
  1359.         if (p == this) {
  1360.         return true;
  1361.         }
  1362.         p = p.getParent();
  1363.     }
  1364.     return false;
  1365.     }
  1366.  
  1367.     /**
  1368.      * Returns the parameter string representing the state of this 
  1369.      * container. This string is useful for debugging. 
  1370.      * @return    the parameter string of this container.
  1371.      */
  1372.     protected String paramString() {
  1373.     String str = super.paramString();
  1374.     LayoutManager layoutMgr = this.layoutMgr;
  1375.     if (layoutMgr != null) {
  1376.         str += ",layout=" + layoutMgr.getClass().getName();
  1377.     }
  1378.     return str;
  1379.     }
  1380.  
  1381.     /**
  1382.      * Prints a listing of this container to the specified output 
  1383.      * stream. The listing starts at the specified indentation. 
  1384.      * @param    out      a print stream.
  1385.      * @param    indent   the number of spaces to indent.
  1386.      * @see      java.awt.Component#list(java.io.PrintStream, int)
  1387.      * @since    JDK
  1388.      */
  1389.     public void list(PrintStream out, int indent) {
  1390.     super.list(out, indent);
  1391.     int ncomponents = this.ncomponents;
  1392.         Component component[] = this.component;
  1393.     for (int i = 0 ; i < ncomponents ; i++) {
  1394.         Component comp = component[i];
  1395.         if (comp != null) {
  1396.         comp.list(out, indent+1);
  1397.         }
  1398.     }
  1399.     }
  1400.  
  1401.     /**
  1402.      * Prints out a list, starting at the specified indention, to the specified
  1403.      * print writer.
  1404.      */
  1405.     public void list(PrintWriter out, int indent) {
  1406.     super.list(out, indent);
  1407.     int ncomponents = this.ncomponents;
  1408.         Component component[] = this.component;
  1409.     for (int i = 0 ; i < ncomponents ; i++) {
  1410.         Component comp = component[i];
  1411.         if (comp != null) {
  1412.         comp.list(out, indent+1);
  1413.         }
  1414.     }
  1415.     }
  1416.  
  1417.     void setFocusOwner(Component c) {
  1418.     Container parent = this.parent;
  1419.     if (parent != null) {
  1420.         parent.setFocusOwner(c);
  1421.     }
  1422.     }
  1423.  
  1424.     void preProcessKeyEvent(KeyEvent e) {
  1425.         Container parent = this.parent;
  1426.         if (parent != null) {
  1427.             parent.preProcessKeyEvent(e);
  1428.         }
  1429.     }
  1430.  
  1431.     void postProcessKeyEvent(KeyEvent e) {
  1432.         Container parent = this.parent;
  1433.         if (parent != null) {
  1434.             parent.postProcessKeyEvent(e);
  1435.         }
  1436.     }
  1437.  
  1438.     void transferFocus(Component base) {
  1439.     nextFocus(base);
  1440.     }
  1441.  
  1442.     boolean postsOldMouseEvents() {
  1443.         return true;
  1444.     }
  1445.  
  1446.     /**
  1447.      * @deprecated As of JDK version 1.1,
  1448.      * replaced by transferFocus(Component).
  1449.      */
  1450.     void nextFocus(Component base) {
  1451.     Container parent = this.parent;
  1452.     if (parent != null) {
  1453.         parent.transferFocus(base);
  1454.     }
  1455.     }
  1456.  
  1457.     /**
  1458.      * Package-visible utility to set the orientation of this container
  1459.      * and all components contained within it.
  1460.      * @since JDK1.2
  1461.      * @see java.awt.Window#applyResourceBundle(java.util.ResourceBundle)
  1462.      */
  1463.     void applyOrientation(ComponentOrientation o) {
  1464.         setComponentOrientation(o);
  1465.         
  1466.         for (int i = 0 ; i < ncomponents ; ++i) {
  1467.             Component comp = component[i];
  1468.             if (comp instanceof Container) {
  1469.                 ((Container)comp).applyOrientation(o);
  1470.             } else {
  1471.                 comp.setComponentOrientation(o);
  1472.             }
  1473.         }
  1474.     }
  1475.     
  1476.     /* Serialization support.  A Container is responsible for
  1477.      * restoring the parent fields of its component children. 
  1478.      */
  1479.     /*
  1480.      * Container Serial Data Version.
  1481.      * @serial
  1482.      */
  1483.     private int containerSerializedDataVersion = 1;
  1484.  
  1485.     /**
  1486.     * Writes default serializable fields to stream.  Writes
  1487.     * a list of serializable ItemListener(s) as optional data.
  1488.     * The non-serializable ItemListner(s) are detected and
  1489.     * no attempt is made to serialize them.
  1490.     *
  1491.     * @serialData Null terminated sequence of 0 or more pairs.
  1492.     *             The pair consists of a String and Object.
  1493.     *             The String indicates the type of object and
  1494.     *             is one of the following :
  1495.     *             itemListenerK indicating and ItemListener object.
  1496.     *
  1497.     * @see AWTEventMulticaster.save(ObjectOutputStream, String, EventListener)
  1498.     * @see java.awt.Component.itemListenerK
  1499.     */
  1500.     
  1501.     private void writeObject(ObjectOutputStream s)
  1502.       throws IOException 
  1503.     {
  1504.       s.defaultWriteObject();
  1505.  
  1506.       AWTEventMulticaster.save(s, containerListenerK, containerListener);
  1507.       s.writeObject(null);
  1508.     }
  1509.  
  1510.     /*
  1511.     * Read the ObjectInputStream and if it isnt null
  1512.     * add a listener to receive item events fired
  1513.     * by the component in the container.
  1514.     * Unrecognised keys or values will be Ignored.
  1515.     * @serial
  1516.     * @see removeActionListener()
  1517.     * @see addActionListener()
  1518.     */
  1519.     private void readObject(ObjectInputStream s)
  1520.       throws ClassNotFoundException, IOException 
  1521.     {
  1522.       s.defaultReadObject();
  1523.  
  1524.       Component component[] = this.component;
  1525.       for(int i = 0; i < ncomponents; i++)
  1526.     component[i].parent = this;
  1527.  
  1528.       Object keyOrNull;
  1529.       while(null != (keyOrNull = s.readObject())) {
  1530.     String key = ((String)keyOrNull).intern();
  1531.  
  1532.     if (containerListenerK == key) 
  1533.       addContainerListener((ContainerListener)(s.readObject()));
  1534.  
  1535.     else // skip value for unrecognized key
  1536.       s.readObject();
  1537.       }
  1538.     }
  1539. }
  1540.  
  1541.  
  1542. /**
  1543.  * Class to manage the dispatching of events to the lightweight
  1544.  * components contained by a native container.
  1545.  * 
  1546.  * @author Timothy Prinzing
  1547.  */
  1548. class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
  1549.  
  1550.     /*
  1551.      * JDK 1.1 serialVersionUID 
  1552.      */
  1553.     private static final long serialVersionUID = 5184291520170872969L;
  1554.     /*
  1555.      * Our own mouse event for when we're dragged over from another hw container
  1556.      */
  1557.     private static final int  LWD_MOUSE_DRAGGED_OVER = AWTEvent.RESERVED_ID_MAX + 1;
  1558.  
  1559.     LightweightDispatcher(Container nativeContainer) {
  1560.     this.nativeContainer = nativeContainer;
  1561.     focus = null;
  1562.     mouseEventTarget = null;
  1563.     eventMask = 0;
  1564.     }
  1565.  
  1566.     /**
  1567.      * Enables events to lightweight components.
  1568.      */
  1569.     void enableEvents(long events) {
  1570.     eventMask |= events;
  1571.     }
  1572.  
  1573.     /**
  1574.      * This is called by the hosting native container on behalf of lightweight 
  1575.      * components that have requested focus.  The focus request is propagated 
  1576.      * upward from the requesting lightweight component until a windowed host 
  1577.      * is found, at which point the windowed host calls this method.  This method 
  1578.      * returns whether or not the peer associated with the native component needs 
  1579.      * to request focus from the native window system. 
  1580.      *
  1581.      * If a lightweight component already has focus the focus events are synthesized 
  1582.      * since there will be no native events to drive the focus.  If the native host 
  1583.      * already has focus, the focus gained is synthesized for the lightweight component 
  1584.      * requesting focus since it will receive no native focus requests.
  1585.      */
  1586.     boolean setFocusRequest(Component c) {
  1587.     boolean peerNeedsRequest = true;
  1588.     Window w = nativeContainer.getWindow();
  1589.     if (w != null && c != null) {
  1590.         Component focusOwner = w.getFocusOwner();
  1591.             if (focusOwner == null) {
  1592.  
  1593.                 // No focus in this component
  1594.                 focus = c;
  1595.  
  1596.             } else if (focusOwner == nativeContainer) {
  1597.         // This container already has focus, so just 
  1598.         // send a FOCUS_LOST event to the container
  1599.                 // and FOCUS_GAINED event to lightweight component
  1600.  
  1601.         nativeContainer.dispatchEvent(new FocusEvent(nativeContainer, FocusEvent.FOCUS_LOST, false));
  1602.         focus = c ;
  1603.         c.dispatchEvent(new FocusEvent(c, FocusEvent.FOCUS_GAINED, false));
  1604.         
  1605.         peerNeedsRequest = false;
  1606.         } else if (focusOwner == c) {
  1607.         // lightweight already has the focus
  1608.         focus = c ;
  1609.         peerNeedsRequest = false;
  1610.         } else if (focusOwner == focus) {
  1611.         // a lightweight component has focus currently and a new one has been
  1612.         // requested.  There won't be any window-system events associated with
  1613.         // this so we go ahead and send FOCUS_LOST for the old and FOCUS_GAINED
  1614.         // for the new.
  1615.         if (focus != null) {
  1616.                     focus.dispatchEvent(new FocusEvent(focus, 
  1617.                                                 FocusEvent.FOCUS_LOST, 
  1618.                                                 false));
  1619.         }
  1620.         focus = c ;
  1621.                 c.dispatchEvent(new FocusEvent(c, FocusEvent.FOCUS_GAINED, false));
  1622.         peerNeedsRequest = false;
  1623.          } else {
  1624.         //Fix for bug 4095214
  1625.         //Paul Sheehan
  1626.         focus = c;
  1627.          }
  1628.        }
  1629.     return peerNeedsRequest;
  1630.     }
  1631.  
  1632.     /**
  1633.      * Dispatches an event to a lightweight sub-component if necessary, and
  1634.      * returns whether or not the event was forwarded to a lightweight
  1635.      * sub-component.
  1636.      *
  1637.      * @param e the event
  1638.      */
  1639.     boolean dispatchEvent(AWTEvent e) {
  1640.     if ((eventMask & PROXY_EVENT_MASK) != 0) {
  1641.         if ((e instanceof MouseEvent) && 
  1642.         ((eventMask & MOUSE_MASK) != 0)) {
  1643.         
  1644.         MouseEvent me = (MouseEvent) e;
  1645.         return processMouseEvent(me);
  1646.  
  1647.         } else if (e instanceof FocusEvent) {
  1648.         
  1649.         FocusEvent fe = (FocusEvent) e;
  1650.         return processFocusEvent(fe);
  1651.  
  1652.         } else if (e instanceof KeyEvent) {
  1653.  
  1654.         KeyEvent ke = (KeyEvent) e;
  1655.         return processKeyEvent(ke);
  1656.  
  1657.         }
  1658.     }
  1659.     return false;
  1660.     }
  1661.  
  1662.     private boolean processKeyEvent(KeyEvent e) {
  1663.     if (focus != null) {
  1664.         // Don't duplicate the event here.
  1665.         // The KeyEvent for LightWeightComponent is also passed to 
  1666.         // input methods and their native handlers. The native handlers
  1667.         // require the original native event data to be attached to
  1668.         // the KeyEvent.
  1669.         Component source = e.getComponent();
  1670.         ((AWTEvent)e).setSource(focus);
  1671.         focus.dispatchEvent(e);
  1672.         ((AWTEvent)e).setSource(source);
  1673.         return e.isConsumed();
  1674.     }
  1675.     return false;
  1676.     }
  1677.     
  1678.     private boolean processFocusEvent(FocusEvent e) {
  1679.     if (focus != null) {
  1680.         int id = e.getID();
  1681.         FocusEvent retargeted = new FocusEvent(focus, id, e.isTemporary());
  1682.         ((AWTEvent)e).copyPrivateDataInto(retargeted);
  1683.         focus.dispatchEvent(retargeted);
  1684.         if ((id == FocusEvent.FOCUS_LOST) && (e.isTemporary() == false)) {
  1685.         focus = null;
  1686.         }
  1687.         return true;
  1688.     }
  1689.     return false;
  1690.     }
  1691.  
  1692.     /**
  1693.      * This method attempts to distribute a mouse event to a lightweight
  1694.      * component.  It tries to avoid doing any unnecessary probes down
  1695.      * into the component tree to minimize the overhead of determining
  1696.      * where to route the event, since mouse movement events tend to
  1697.      * come in large and frequent amounts.
  1698.      */
  1699.     private boolean processMouseEvent(MouseEvent e) {
  1700.     int id = e.getID();
  1701.     Component targetOver;
  1702.     Component lwOver;
  1703.  
  1704.     targetOver = nativeContainer.getMouseEventTarget(e.getX(), e.getY(),true);
  1705.     trackMouseEnterExit(targetOver, e);
  1706.  
  1707.     if (mouseEventTarget == null) {
  1708.         if ( id == MouseEvent.MOUSE_MOVED ||
  1709.              id == MouseEvent.MOUSE_PRESSED ) {
  1710.         lwOver = (targetOver != nativeContainer) ? targetOver : null;
  1711.         setMouseTarget(lwOver,e);
  1712.         }
  1713.     }
  1714.  
  1715.     if (mouseEventTarget != null) {
  1716.         // we are currently forwarding to some component, check
  1717.         // to see if we should continue to forward.
  1718.         switch(id) {
  1719.         case MouseEvent.MOUSE_DRAGGED:
  1720.         if(dragging) {
  1721.             retargetMouseEvent(mouseEventTarget, id, e);
  1722.         }
  1723.         break;
  1724.         case MouseEvent.MOUSE_PRESSED:
  1725.         dragging = true;
  1726.         retargetMouseEvent(mouseEventTarget, id, e);
  1727.         break;
  1728.         case MouseEvent.MOUSE_RELEASED:
  1729.         {
  1730.         Component releasedTarget = mouseEventTarget;
  1731.         dragging = false;
  1732.         retargetMouseEvent(mouseEventTarget, id, e);
  1733.         lwOver = nativeContainer.getMouseEventTarget(e.getX(), e.getY(),false);
  1734.         setMouseTarget(lwOver, e);
  1735.         if (lwOver != releasedTarget) {
  1736.         // fix 4155217
  1737.         // component was hidden or moved in user code MOUSE_RELEASED handling
  1738.             isClickOrphaned = true;
  1739.         }
  1740.         break;
  1741.         }
  1742.         
  1743.         case MouseEvent.MOUSE_CLICKED:
  1744.         if (!isClickOrphaned) {
  1745.         // fix 4155217
  1746.         // click event should not be redirected since component has moved or hidden
  1747.             retargetMouseEvent(mouseEventTarget, id, e);
  1748.         }
  1749.         isClickOrphaned = false;
  1750.         break;
  1751.         case MouseEvent.MOUSE_ENTERED:
  1752.         break;
  1753.         case MouseEvent.MOUSE_EXITED:
  1754.         if (!dragging) {
  1755.             setMouseTarget(null, e);
  1756.         }
  1757.         break;
  1758.         case MouseEvent.MOUSE_MOVED:
  1759.         lwOver = nativeContainer.getMouseEventTarget(e.getX(), e.getY(),false);
  1760.         setMouseTarget(lwOver, e);
  1761.         retargetMouseEvent(mouseEventTarget, id, e);
  1762.         break;
  1763.         }
  1764.         e.consume();
  1765.     }
  1766.  
  1767.     return e.isConsumed();
  1768.     }
  1769.  
  1770.     /**
  1771.      * Change the current target of mouse events.
  1772.      */
  1773.     private void setMouseTarget(Component target, MouseEvent e) {
  1774.     if (target != mouseEventTarget) {
  1775.         //System.out.println("setMouseTarget: " + target);
  1776.         mouseEventTarget = target;
  1777.     }
  1778.     }
  1779.  
  1780.     /*
  1781.      * Generates enter/exit events as mouse moves over lw components
  1782.      * @param targetOver    Target mouse is over (including native container)
  1783.      * @param e            Mouse event in native container
  1784.      */
  1785.     private void trackMouseEnterExit(Component targetOver, MouseEvent e) {
  1786.     Component    targetEnter = null;
  1787.     int        id = e.getID();
  1788.  
  1789.     if ( id != MouseEvent.MOUSE_EXITED &&
  1790.          id != MouseEvent.MOUSE_DRAGGED &&
  1791.          id != LWD_MOUSE_DRAGGED_OVER &&
  1792.          isMouseInNativeContainer == false ) {
  1793.         // any event but an exit or drag means we're in the native container
  1794.         isMouseInNativeContainer = true;
  1795.         startListeningForOtherDrags();
  1796.     } else if ( id == MouseEvent.MOUSE_EXITED ) {
  1797.         isMouseInNativeContainer = false;
  1798.         stopListeningForOtherDrags();
  1799.     }
  1800.  
  1801.     if (isMouseInNativeContainer) {
  1802.         targetEnter = targetOver;
  1803.     }
  1804.     //System.out.println("targetEnter = " + targetEnter);
  1805.     //System.out.println("targetLastEntered = " + targetLastEntered);
  1806.  
  1807.     if (targetLastEntered == targetEnter) {
  1808.         return;
  1809.     }
  1810.  
  1811.     retargetMouseEvent(targetLastEntered, MouseEvent.MOUSE_EXITED, e);
  1812.     if (id == MouseEvent.MOUSE_EXITED) {
  1813.         // consume native exit event if we generate one
  1814.         e.consume();
  1815.     }
  1816.  
  1817.     retargetMouseEvent(targetEnter, MouseEvent.MOUSE_ENTERED, e);
  1818.     if (id == MouseEvent.MOUSE_ENTERED) {
  1819.         // consume native enter event if we generate one
  1820.         e.consume();
  1821.     }
  1822.  
  1823.     //System.out.println("targetLastEntered: " + targetLastEntered);
  1824.     targetLastEntered = targetEnter;
  1825.     }
  1826.  
  1827.     private void startListeningForOtherDrags() {
  1828.     //System.out.println("Adding AWTEventListener");
  1829.     java.security.AccessController.doPrivileged(
  1830.         new java.security.PrivilegedAction() {
  1831.         public Object run() {
  1832.             nativeContainer.getToolkit().addAWTEventListener(
  1833.                 LightweightDispatcher.this,
  1834.             AWTEvent.MOUSE_EVENT_MASK |
  1835.             AWTEvent.MOUSE_MOTION_EVENT_MASK);
  1836.             return null;
  1837.         }
  1838.         }
  1839.     );
  1840.     }
  1841.  
  1842.     private void stopListeningForOtherDrags() {
  1843.     //System.out.println("Removing AWTEventListener");
  1844.     java.security.AccessController.doPrivileged(
  1845.         new java.security.PrivilegedAction() {
  1846.         public Object run() {
  1847.             nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this);
  1848.             return null;
  1849.         }
  1850.         }
  1851.     );
  1852.     }
  1853.  
  1854.     /*
  1855.      * (Implementation of AWTEventListener)
  1856.      * Listen for drag events posted in other hw components so we can
  1857.      * track enter/exit regardless of where a drag originated
  1858.      */
  1859.     public void eventDispatched(AWTEvent e) {
  1860.     boolean isForeignDrag = (e instanceof MouseEvent) &&
  1861.                 (e.id == MouseEvent.MOUSE_DRAGGED) &&
  1862.                 (e.getSource() != nativeContainer);
  1863.     
  1864.     if (!isForeignDrag) {
  1865.         // only interested in drags from other hw components
  1866.         return;
  1867.     }
  1868.  
  1869.     MouseEvent    srcEvent = (MouseEvent)e;
  1870.     MouseEvent    me;
  1871.  
  1872.     synchronized (nativeContainer.getTreeLock()) {
  1873.         Component srcComponent = srcEvent.getComponent();
  1874.  
  1875.         // component may have disappeared since drag event posted
  1876.         // (i.e. Swing hierarchical menus)
  1877.         if ( !srcComponent.isShowing() ||
  1878.          !nativeContainer.isShowing() ) {
  1879.         return;
  1880.         }
  1881.  
  1882.         //
  1883.         // create an internal 'dragged-over' event indicating
  1884.         // we are being dragged over from another hw component
  1885.         //
  1886.         me = new MouseEvent(nativeContainer,
  1887.                    LWD_MOUSE_DRAGGED_OVER,
  1888.                    srcEvent.getWhen(),
  1889.                    srcEvent.getModifiers(),
  1890.                    srcEvent.getX(),
  1891.                    srcEvent.getY(),
  1892.                    srcEvent.getClickCount(),
  1893.                    srcEvent.isPopupTrigger());
  1894.         ((AWTEvent)srcEvent).copyPrivateDataInto(me);
  1895.         // translate coordinates to this native container
  1896.         Point    ptSrcOrigin = srcComponent.getLocationOnScreen();
  1897.         Point    ptDstOrigin = nativeContainer.getLocationOnScreen();
  1898.         me.translatePoint( ptSrcOrigin.x - ptDstOrigin.x, ptSrcOrigin.y - ptDstOrigin.y );
  1899.     }
  1900.     //System.out.println("Track event: " + me);
  1901.     // feed the 'dragged-over' event directly to the enter/exit
  1902.     // code (not a real event so don't pass it to dispatchEvent)
  1903.     Component targetOver = nativeContainer.getMouseEventTarget(me.getX(), me.getY(), true);
  1904.     trackMouseEnterExit(targetOver, me);
  1905.     }
  1906.  
  1907.     /**
  1908.      * Sends a mouse event to the current mouse event recipient using
  1909.      * the given event (sent to the windowed host) as a srcEvent.  If
  1910.      * the mouse event target is still in the component tree, the 
  1911.      * coordinates of the event are translated to those of the target.
  1912.      * If the target has been removed, we don't bother to send the
  1913.      * message.
  1914.      */
  1915.     void retargetMouseEvent(Component target, int id, MouseEvent e) {
  1916.     if (target == null) {
  1917.         return; // mouse is over another hw component
  1918.     }
  1919.  
  1920.         int x = e.getX(), y = e.getY();
  1921.         Component component;
  1922.  
  1923.         for(component = target;
  1924.             component != null && component != nativeContainer;
  1925.             component = component.getParent()) {
  1926.             x -= component.x;
  1927.             y -= component.y;
  1928.         }
  1929.         if (component != null) {
  1930.             MouseEvent retargeted = new MouseEvent(target,
  1931.                                                    id, 
  1932.                                                    e.getWhen(), 
  1933.                                                    e.getModifiers(),
  1934.                                                    x, 
  1935.                                                    y, 
  1936.                                                    e.getClickCount(), 
  1937.                                                    e.isPopupTrigger());
  1938.         ((AWTEvent)e).copyPrivateDataInto(retargeted);
  1939.  
  1940.         if (target == nativeContainer) {
  1941.         // avoid recursively calling LightweightDispatcher...
  1942.         ((Container)target).dispatchEventToSelf(retargeted);
  1943.         } else {
  1944.         target.dispatchEvent(retargeted);
  1945.         }
  1946.  
  1947.             // update cursor if needed.  This is done after the event has
  1948.             // been sent to the target so the target has a chance to change
  1949.             // the cursor after reacting to the event.
  1950.         Cursor c = target.getCursor();
  1951.         if (nativeContainer.getCursor() != c) {
  1952.         //System.out.println("Setting cursor to: " + c.getType());
  1953.         nativeContainer.setCursor(c);
  1954.         }
  1955.         }
  1956.     }
  1957.     
  1958.     // --- member variables -------------------------------
  1959.  
  1960.     /**
  1961.      * The windowed container that might be hosting events for 
  1962.      * lightweight components.
  1963.      */
  1964.     private Container nativeContainer;
  1965.  
  1966.     /**
  1967.      * The current lightweight component that has focus that is being
  1968.      * hosted by this container.  If this is a null reference then 
  1969.      * there is currently no focus on a lightweight component being 
  1970.      * hosted by this container 
  1971.      */
  1972.     private Component focus;
  1973.  
  1974.     /**
  1975.      * The current lightweight component being hosted by this windowed
  1976.      * component that has mouse events being forwarded to it.  If this
  1977.      * is null, there are currently no mouse events being forwarded to 
  1978.      * a lightweight component.
  1979.      */
  1980.     private transient Component mouseEventTarget;
  1981.  
  1982.     /**
  1983.      * The last component entered
  1984.      */
  1985.     private transient Component targetLastEntered;
  1986.  
  1987.     /**
  1988.      * Is the mouse over the native container
  1989.      */
  1990.     private transient boolean isMouseInNativeContainer = false;
  1991.  
  1992.     /**
  1993.      * Is the next click event orphaned because the component hid/moved
  1994.      */
  1995.     private transient boolean isClickOrphaned = false;
  1996.  
  1997.     /**
  1998.      * Indicates if the mouse pointer is currently being dragged...
  1999.      * this is needed because we may receive exit events while dragging
  2000.      * and need to keep the current mouse target in this case.
  2001.      */
  2002.     private boolean dragging;
  2003.  
  2004.     /**
  2005.      * The cursor used by the native container that is hosting the
  2006.      * lightweight components.  Since the Cursor used by the lightweight
  2007.      * components overwrites the Cursor set in the native container
  2008.      * we need to stash the native cursor so we can restore it after
  2009.      * the lightweight components are done having their cursor shown.
  2010.      */
  2011.     private Cursor nativeCursor;
  2012.  
  2013.     /**
  2014.      * The event mask for contained lightweight components.  Lightweight
  2015.      * components need a windowed container to host window-related 
  2016.      * events.  This seperate mask indicates events that have been 
  2017.      * requested by contained lightweight components without effecting
  2018.      * the mask of the windowed component itself.
  2019.      */
  2020.     private long eventMask;
  2021.  
  2022.     /**
  2023.      * The kind of events routed to lightweight components from windowed
  2024.      * hosts.
  2025.      */
  2026.     private static final long PROXY_EVENT_MASK =
  2027.         AWTEvent.FOCUS_EVENT_MASK | 
  2028.         AWTEvent.KEY_EVENT_MASK |
  2029.         AWTEvent.MOUSE_EVENT_MASK | 
  2030.         AWTEvent.MOUSE_MOTION_EVENT_MASK;
  2031.  
  2032.     private static final long MOUSE_MASK = 
  2033.         AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK;
  2034. }
  2035.